import { RouteRecordRaw } from "vue-router";
import { HOME_URL, LOGIN_URL } from "@/config";
import { routeMenuConfig } from "@/config/route";

/**
 * staticRouter (静态路由)
 */
export const staticRouter: RouteRecordRaw[] = [
  {
    path: "/",
    redirect: HOME_URL
  },
  {
    path: LOGIN_URL,
    name: "login",
    component: () => import("@/views/login/index.vue"),
    meta: {
      title: "登录"
    }
  },
  {
    path: "/modify_password",
    name: "modify_password",
    component: () => import("@/views/login/modify_password.vue"),
    meta: {
      title: "修改密码"
    }
  }
  // {
  //   path: "/layout",
  //   name: "layout",
  //   component: () => import("@/layouts/index.vue"),
  //   // component: () => import("@/layouts/indexAsync.vue"),
  //   redirect: HOME_URL,
  //   children: [
  //     {
  //       path: "/overview",
  //       name: "webPortal",
  //       component: () => import("@/views/webPortal/overview/index.vue"),
  //       meta: {
  //         title: "首页",
  //         label: "首页"
  //       }
  //     },
  //     {
  //       path: "/log_management",
  //       name: "sysManagement_log",
  //       component: () => import("@/views/sysManagement/log_management/index.vue"),
  //       meta: {
  //         title: "日志管理",
  //         label: "日志管理"
  //       }
  //     },
  //     {
  //       path: "/role_management",
  //       name: "sysManagement_role",
  //       component: () => import("@/views/sysManagement/role_management/index.vue"),
  //       meta: {
  //         title: "角色管理",
  //         label: "角色管理"
  //       }
  //     },
  //     {
  //       path: "/sys_setting",
  //       name: "sysManagement_setting",
  //       component: () => import("@/views/sysManagement/sys_setting/index.vue"),
  //       meta: {
  //         title: "系统设置",
  //         label: "系统设置"
  //       }
  //     },
  //     {
  //       path: "/thirdParty_management",
  //       name: "sysManagement_thirdParty",
  //       component: () => import("@/views/sysManagement/thirdParty_management/index.vue"),
  //       meta: {
  //         title: "第三方管理",
  //         label: "第三方管理"
  //       }
  //     },
  //     {
  //       path: "/user_management",
  //       name: "sysManagement_user",
  //       component: () => import("@/views/sysManagement/user_management/index.vue"),
  //       meta: {
  //         title: "用户管理",
  //         label: "用户管理"
  //       }
  //     },
  //     {
  //       path: "/route_management",
  //       name: "sysManagement_route",
  //       component: () => import("@/views/sysManagement/route_management/index.vue"),
  //       meta: {
  //         title: "线路管理",
  //         label: "线路管理"
  //       }
  //     },
  //     {
  //       path: "/screen",
  //       name: "sysManagement_screen",
  //       component: () => import("@/views/sysManagement/large_screen/index.vue"),
  //       meta: {
  //         title: "大屏可视",
  //         label: "大屏可视"
  //       }
  //     },
  //     {
  //       path: "/assetManagement",
  //       name: "asset_assetManagement",
  //       component: () => import("@/views/asset/asset_overview/index.vue"),
  //       meta: {
  //         title: "资产管理",
  //         label: "资产管理"
  //       }
  //     },
  //     {
  //       path: "/baseData",
  //       name: "asset_baseData",
  //       component: () => import("@/views/asset/base_data/index.vue"),
  //       meta: {
  //         title: "基础数据",
  //         label: "基础数据"
  //       }
  //     },
  //     {
  //       path: "/",
  //       redirect: "/user_management"
  //     }
  //   ]
  // }
];

/**
 * errorRouter (错误页面路由)
 */
export const errorRouter = [
  {
    path: "/403",
    name: "403",
    component: () => import("@/components/ErrorMessage/403.vue"),
    meta: {
      title: "403页面"
    }
  },
  {
    path: "/404",
    name: "404",
    component: () => import("@/components/ErrorMessage/404.vue"),
    meta: {
      title: "404页面"
    }
  },
  {
    path: "/500",
    name: "500",
    component: () => import("@/components/ErrorMessage/500.vue"),
    meta: {
      title: "500页面"
    }
  },
  // Resolve refresh page, route warnings
  {
    path: "/:pathMatch(.*)*",
    component: () => import("@/components/ErrorMessage/404.vue")
  }
];

export const dynamicRouters = () => {
  let router = {
    path: "/layout",
    name: "layout",
    component: () => import("@/layouts/index.vue"),
    redirect: HOME_URL,
    children: []
  };
  Object.keys(routeMenuConfig).forEach(item => {
    router.children = router.children.concat(routeMenuConfig[item]);
  });
  return [router];
};
